package ioc

import (
	"github.com/IBM/sarama"
	"github.com/spf13/viper"
	"jk-time/webook/pkg/saramax"
)

func InitKafka() sarama.Client {
	host := viper.GetString("kafka.host")
	cfg := sarama.NewConfig()
	cfg.Producer.Return.Successes = true
	cfg.Producer.Return.Errors = true

	client, err := sarama.NewClient([]string{host}, cfg)
	if err != nil {
		panic(err)
	}
	return client
}
func NewSyncProducer(client sarama.Client) sarama.SyncProducer {
	res, err := sarama.NewSyncProducerFromClient(client)
	if err != nil {
		panic(err)
	}
	return res
}
func NewConsumer(comsumer saramax.Comsumer) []saramax.Comsumer {
	return []saramax.Comsumer{comsumer}
}
